2020-2021 Sunseeker Telemetry and Lighting System
comp_e_ex3_interruptVcompVs12V.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
33 // MSP430FR5969 Demo - COMPE interrupt capability; Vcompare is compared against
34 // internal 1.2V reference
35 //
36 // Description: Use COMPE and internal reference to determine if input'Vcompare'
37 // is high of low. For the first time, when Vcompare exceeds the 1.2V internal
38 // reference, CEIFG is set and device enters the COMPE ISR. In the ISR, CEIES is
39 // toggled such that when Vcompare is less than 1.2V internal reference;
40 // CEIFG is set.
41 // LED is toggled inside the COMPE ISR
42 //
43 // MSP430FR5969
44 // ------------------
45 // /|\| |
46 // | | |
47 // --|RST P3.1/CE13|<--Vcompare
48 // | |
49 // | P3.4|----> 'high'(Vcompare>1.2V); 'low'(Vcompare<1.2V)
50 // | | |
51 // | | | LED 'ON'(Vcompare>1.2V); 'OFF'(Vcompare<1.2V)
52 // | |
53 //
54 //******************************************************************************
55 #include "driverlib.h"
56 
57 void main (void)
58 {
59  //Stop WDT
60  WDT_A_hold(WDT_A_BASE);
61 
62  //Set P3.4 as an output pin.
63  /*
64 
65  * Select Port 3
66  * Set Pin 4 as output
67  */
68  GPIO_setAsOutputPin(
69  GPIO_PORT_P3,
70  GPIO_PIN4
71  );
72  //Set P3.4 as Output Low.
73  /*
74 
75  * Select Port 3
76  * Set Pin 4 to output Low.
77  */
79  GPIO_PORT_P3,
80  GPIO_PIN4
81  );
82 
83  /*
84  * Disable the GPIO power-on default high-impedance mode to activate
85  * previously configured port settings
86  */
87  PMM_unlockLPM5();
88 
89  //Initialize the Comparator E module
90  /*
91  * Base Address of Comparator E,
92  * Pin CE13 to Positive(+) Terminal
93  * Reference Voltage to Negative(-) Terminal
94  * Normal Power Mode
95  * Output Filter On with minimal delay
96  * Non-Inverted Output Polarity
97  */
98  Comp_E_initParam param = {0};
99  param.posTerminalInput = COMP_E_INPUT13;
100  param.negTerminalInput = COMP_E_VREF;
101  param.outputFilterEnableAndDelayLevel = COMP_E_FILTEROUTPUT_OFF;
102  param.invertedOutputPolarity = COMP_E_NORMALOUTPUTPOLARITY;
103  Comp_E_init(COMP_E_BASE, &param);
104 
105  //Set the reference voltage that is being supplied to the (-) terminal
106  /*
107  * Base Address of Comparator E,
108  * Reference Voltage of 1.5 V,
109  * Lower Limit of 1.2*(32/32) = 1.2V,
110  * Upper Limit of 1.2*(32/32) = 1.2V
111  */
112  Comp_E_setReferenceVoltage(COMP_E_BASE,
113  COMP_E_VREFBASE1_2V,
114  32,
115  32
116  );
117 
118  //Enable COMP_E Interrupt on default rising edge for CEIFG
119  Comp_E_setInterruptEdgeDirection(COMP_E_BASE, COMP_E_RISINGEDGE);
120 
121  // Clear any erroneous interrupts
122  Comp_E_clearInterrupt(COMP_E_BASE, (COMP_E_OUTPUT_INTERRUPT_FLAG + COMP_E_INTERRUPT_FLAG_INVERTED_POLARITY));
123 
124  //Enable Interrupts
125  /*
126  * Base Address of Comparator E,
127  * Enable COMPE Interrupt on default rising edge for CEIFG
128  */
129 
130  Comp_E_clearInterrupt(COMP_E_BASE,
131  COMP_E_OUTPUT_INTERRUPT_FLAG
132  );
133 
134  Comp_E_enableInterrupt(COMP_E_BASE,
135  COMP_E_OUTPUT_INTERRUPT
136  );
137 
138  //Allow power to Comparator module
139  Comp_E_enable(COMP_E_BASE);
140 
141  //Enter LPM4 with interrupts enabled
142  __bis_SR_register(LPM4_bits + GIE);
143 
144  //For debug
145  __no_operation();
146 }
147 
148 //******************************************************************************
149 //
150 //This is the COMP_E_VECTOR interrupt vector service routine.
151 //
152 //******************************************************************************
153 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
154 #pragma vector=COMP_E_VECTOR
155 __interrupt
156 #elif defined(__GNUC__)
157 __attribute__((interrupt(COMP_E_VECTOR)))
158 #endif
159 void COMP_E_ISR (void)
160 {
161  //Toggle the edge at which an interrupt is generated
162  Comp_E_toggleInterruptEdgeDirection(COMP_E_BASE);
163 
164  //Clear Interrupt flag
165  Comp_E_clearInterrupt(COMP_E_BASE, COMP_E_OUTPUT_INTERRUPT_FLAG);
166 
167  //Toggle P3.4 output pin.
168  /*
169 
170  * Select Port 3
171  * Set Pin 4 as output
172  */
173  GPIO_toggleOutputOnPin(
174  GPIO_PORT_P3,
175  GPIO_PIN4
176  );
177 }
MPU_initThreeSegmentsParam param
void main(void)
void COMP_E_ISR(void)
__no_operation()
GPIO_setOutputLowOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)